home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Libraries / Runtime / Common Sources / MWException.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  3.9 KB  |  109 lines  |  [TEXT/MMCC]

  1. /************************************************************************/
  2. /*    Project...:    Standard C++ Library                                    */
  3. /*    Name......:    MWException.h                                            */
  4. /*    Purpose...:    portable exception handling                                */
  5. /*  Copyright.: ©Copyright 1993-95 by metrowerks inc                    */
  6. /************************************************************************/
  7.  
  8. #define CATCH_BUFSIZE    128                    //    size of global catch buffer
  9.  
  10. #if        defined(__MC68K__)
  11.  
  12.     #define CATCH_REGBUFSIZE    (10)        //    D3-D7,A2-A4,A6,SP
  13.  
  14. #elif    defined(__POWERPC__)
  15.  
  16.     #define CATCH_REGBUFSIZE    (70)        //    ???
  17.  
  18. #elif    defined(__INTEL__)
  19.  
  20.     #define CATCH_REGBUFSIZE    (10)        //    ???
  21.  
  22. #else
  23. #error
  24. #endif
  25.  
  26. ////    [this section is copied from CException.h
  27.  
  28. typedef enum ExceptionElementType {
  29.     EET_AUTODESTROY,        //    (partly) constructed automatic object that needs to be destroyed
  30.     EET_TEMPDESTROY,        //    (partly) constructed temporary object that will need destruction
  31.     EET_PRETEMPDESTROY,        //    unconstructed temporary object that will need destruction
  32.     EET_CATCHBLOCK            //    catch block type
  33. }    ExceptionElementType;
  34.  
  35. typedef long CatchRegBuffer[CATCH_REGBUFSIZE];    //    buffer to store non-volatile registers
  36.  
  37. typedef struct CatchData {
  38.     void                    *catch_pc;        //    pointer to catch block pc
  39.     CatchRegBuffer            *catch_buffer;    //    pointer to catch jmp_buf
  40.     char                    last_catch;        //    true: a try block's last catcher
  41.     char                    reserved;        //    reserved
  42. }    CatchData;
  43.  
  44. typedef struct ExceptionElement {
  45.     struct ExceptionElement    *next;            //    pointer to next ExceptionElement
  46.     union {
  47.         struct {                            //    type == { EET_AUTODESTROY || EET_TEMPDESTROY || EET_PREAUTODESTROY }
  48.             void            *destructor;    //    pointer to destructor function
  49.             void            *object;        //    pointer to memory location
  50.         }    autodestroy;
  51.  
  52.         struct {                            //    type == { EET_CATCHBLOCK }
  53.             char            *catchtype;        //    pointer to catch type string
  54.             CatchData        *catchdata;        //    pointer to catch data block
  55.         }    catchblock;
  56.     }    data;                                //    sizeof (union data) == 2 * sizeof(void *)
  57.     unsigned short            type;            //    exception type one of: { ExceptionElementType }
  58. }    ExceptionElement;
  59.  
  60. ////    this section is copied from CException.h]
  61.  
  62. typedef struct ExceptionState {                //    exception context state
  63.     ExceptionElement    *ldc_save;            //    __local_destructor_chain
  64.     void                *cb_save;            //    __catch_buffer
  65.     void                *cvp_save;            //    __catch_var_pointer
  66.     char                *tt_save;            //    __throw_type
  67.     void                *reserved;            //    reserved
  68. }    ExceptionState;
  69.  
  70. typedef struct DestructorChain {            //    global destructor chain
  71.     struct DestructorChain    *next;            //    pointer to next destructor chain element
  72.     void                    *destructor;    //    pointer to destructor function
  73.     void                    *object;        //    pointer to memory location (0L: element is marker)
  74. }    DestructorChain;
  75.  
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79.  
  80. extern DestructorChain    *__global_destructor_chain;
  81. extern ExceptionElement    *__local_destructor_chain;
  82. extern void                *__catch_buffer;
  83. extern void                *__catch_var_pointer;
  84.  
  85. extern void        *__register_global_object(void *object,void *destructor,void *regmem);
  86. extern void        *__register_temp_object(void *object,void *destructor,void *regmem);
  87. extern void        *__register_auto_object(void *object,void *destructor,void *regmem);
  88. extern void        *__preregister_temp_object(void *object,void *destructor,void *regmem);
  89. extern void        *__reregister_temp_object(void *regmem);
  90.  
  91. extern void        __destroy_global_chain(void);
  92. extern void        __destroy_temp_objects(void *regmem);
  93. extern void        __destroy_autotemp_objects(void *regmem);
  94. extern void        __destroy_autotemp_objects_to(void *regmem);
  95. extern void        __destroy_local_chain(void);
  96. extern void        __dummy(void);
  97.  
  98. extern void        __throw(char *);
  99. extern void        __install_catcher(long,ExceptionElement *,CatchData *,CatchRegBuffer *,void *,char *);
  100. extern void        __setup_catchregbuffer(CatchRegBuffer *);
  101. extern void        __catch_jump(CatchRegBuffer *,void *);
  102.  
  103. extern void        __new_exception_state(ExceptionState *newp,char *buffer);
  104. extern void        __switch_exception_state(ExceptionState *newp,ExceptionState *curp);
  105.  
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109.